package com.qining618.cms.ucenter.mapper;

import com.qining618.cms.ucenter.domain.RoleMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 角色菜单 Mapper 接口
 * </p>
 *
 * @author qining
 * @date 2019-09-16
 */
@Mapper
@Repository
public interface RoleMenuMapper extends BaseMapper<RoleMenu> {

    /**
     * 根据菜单id删除角色菜单信息
     * @param menuId 菜单id
     * @return int
     */
    @Delete("delete from o_role_menu where menu_id = #{menuId}")
    int deleteByMenuId(@Param("menuId") Long menuId);

    /**
     * 根据角色id删除角色菜单信息
     * @param roleId 角色id
     * @return int
     */
    @Delete("delete from o_role_menu where role_id = #{roleId}")
    int deleteByRoleId(@Param("roleId") Long roleId);

    /**
     * 根据角色id获取菜单编号
     * @param roleId 角色id
     * @return List&lt;String&gt; 菜单编号
     */
    @Select("select om.code from o_role_menu orm left join o_menu om on orm.menu_id = om.id" +
            " where orm.role_id = #{roleId}")
    List<String> findMenuCodeByRoleId(@Param("roleId") Long roleId);
}
